#include <bitset>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <map>

using namespace std;

#define UNITS 10

typedef unsigned long ULL;

//map<ULL, ULL> CACHE;
ULL *CACHE;

ULL mod(ULL i, ULL m)
{
	ULL temp1 = (ULL)pow(CACHE[UNITS] % m, i/UNITS);
	ULL temp2 = CACHE[i%UNITS] % m;
	
	return (temp1 * temp2) % m;
}

int main()
{
	ULL k, m;
	cin >> k >> m;
	
	CACHE = new ULL[UNITS+1];
	
	for (int i=0; i<=UNITS; ++i)
	{
		CACHE[i] = (ULL)pow(10, i) % m;
	}
		
	ULL _mod = 0;
	
	for (int i=0; ; ++i)
	{
		_mod += mod(i, m);
		if (_mod % m == k % m)
		{
			cout << i+1 << endl;
			return 0;
		}
	}
	
	return 0;
}